# -*- coding: utf-8 -*-
from django import forms
from django.forms import ModelForm
from django.forms.fields import MultipleChoiceField, FileField
from django.forms.widgets import Textarea, CheckboxSelectMultiple, \
    SelectMultiple, Select, DateInput, FileInput, Widget
from models import InformePais
from universidades.models import Region, Universidad, Pais_region
from usuarios.models import Usuario


class InformePaisForm( forms.ModelForm ):

    def save( self, user, pais_informe, *args, **kwargs ):
        commit = kwargs.pop( 'commit', True )
        instance = super( InformePaisForm, self ).save( *args, commit = False, **kwargs )
        instance.usuario = user
        instance.pais = pais_informe

        if commit:
            instance.save()

        return instance

    class Media:
        css = { 'all' : ('css/spacelab.css','css/responsive.css','css/misestilos.css','css/datepicker.css') }
        js = ('js/jquery-1.10.2.min.js','js/bootstrap.js','js/bootstrap-datepicker.js','js/jquery.form-validator.min.js', 'js/informes_pais_form.js')

    class Meta:
        model = InformePais
        fields = ( 'fecha_inicio', 'fecha_fin' , 'resumen', 'archivo' )
        widgets = {
            'resumen': Textarea( attrs = {'cols': 200,
                                          'rows': 10,
                                          'class':'textarea.span5' ,
                                          'placeholder': 'Redacte un breve resumen del informe a nivel pais.',
#                                           'data-validation':"length",
#                                           'data-validation-length':"min30",
#                                           'data-validation-error-msg':"Favor complete correctamente el resumen del informe. Se require como minimo 30 caracteres."
                                        } ),
            'fecha_inicio' : DateInput( attrs = { 'value': '',
                                                 'class':'datePicker',
                                                 'placeholder': u'DIA/MES/AÑO',
                                                 'data-date-format':"dd/mm/yyyy" ,
                                                } ),
            'fecha_fin' : DateInput( attrs = { 'value': '',
                                              'class':'datePicker',
                                              'placeholder': u'DIA/MES/AÑO' ,
                                              'data-date-format':"dd/mm/yyyy" ,
                                              } ),
            'archivo': FileInput( attrs = { } ),
        }
